package com.fyfeng.java.bootwrapper.conf;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

public class Configuration {

	private Properties prop = new Properties();

	public Configuration() {
		InputStream inStream = ClassLoader.getSystemResourceAsStream("server.properties");
		try {
			prop.load(inStream);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				inStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Set<String> keySet(){
		Enumeration<Object> enums = prop.keys();
		HashSet<String> hset = new HashSet<String>();
		while(enums.hasMoreElements()){
			hset.add(String.valueOf(enums.nextElement()));
		}
		return hset;
	}

	public String getString(String key) {
		return prop.getProperty(key);
	}

	public int getInt(String key) {
		return Integer.valueOf(prop.getProperty(key));
	}

	public long getLong(String key) {
		return Long.valueOf(prop.getProperty(key));
	}

	public boolean getBoolean(String key) {
		return Boolean.valueOf(prop.getProperty(key));
	}
}
